package com.langfeiyes.pattern.memento.demo;

public class App {
    public static void main(String[] args) {

        //原发器
        Originator originator = new Originator();
        //备份录管理器
        Caretaker caretaker = new Caretaker();
        //一系列操作后，原发器设置状态1
        originator.setState("state1");
        //备份1
        caretaker.addMemento(originator.createMemento());
        System.out.println("当前原发器状态：" + originator.getState() + ", 备份");
        //又一系列操作后，原发器设置状态2
        originator.setState("state2");
        caretaker.addMemento(originator.createMemento());
        System.out.println("当前原发器状态：" + originator.getState() + ", 备份");
        //又一系列操作后，原发器设置状态3
        originator.setState("state3");
        caretaker.addMemento(originator.createMemento());
        System.out.println("当前原发器状态：" + originator.getState() + ", 备份");

        //遍历备忘录集合
        caretaker.showMemento();


        //恢复备忘录....................
        originator.setMemento(caretaker.retriveMemento());
        System.out.println("第一次恢复备忘录，原发器状态：" + originator.getState());
        originator.setMemento(caretaker.retriveMemento());
        System.out.println("第二次恢复备忘录，原发器状态：" + originator.getState());
        originator.setMemento(caretaker.retriveMemento());
        System.out.println("第三次恢复备忘录，原发器状态：" + originator.getState());

    }
}
